package com.ztgf.shopping.api.client.shop;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import com.ztgf.shopping.models.bo.shop.ShopCategoryRelationAuditSaveListBO;
import com.ztgf.shopping.models.dto.shop.ShopCategoryRelationAuditDTO;
import com.ztgf.shopping.models.service.shop.IShopCategoryRelationAuditService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 店铺品牌分类审核控制器
 *
 * @author zhanghualang
 * @Date 2020-06-24 11:11:48
 */

@RestController
@RequestMapping("/api/shopCategoryRelationAudit")
@Slf4j
@Api(value = "ShopCategoryRelationAuditApiController",tags = "店铺品牌分类审核Api接口")
public class ShopCategoryRelationAuditApiController {

    @DubboReference
    private IShopCategoryRelationAuditService shopCategoryRelationAuditService;

    @PostMapping("/get")
    @ApiOperation(value = "根据id查找",notes = "根据id查找")
    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
    public Result<ShopCategoryRelationAuditDTO> get(@RequestParam("id") Long id){
        if(id == null){
            return new Result<>(CodeEnum.FAIL_100002 );
        }

        ShopCategoryRelationAuditDTO dto = shopCategoryRelationAuditService.selectById(id);

        return new Result<>(dto);
    }

    @ApiOperation(value = "店铺品牌分类审核列表",notes = "店铺品牌分类审核列表")
    @PostMapping("/queryPageList")
    public Result<List<ShopCategoryRelationAuditDTO>> queryPageList(Long shopId, Long brandId){
        if(shopId == null || brandId == null){
            return new Result<>(CodeEnum.FAIL_100002 );
        }
        Wrapper<ShopCategoryRelationAuditDTO> wrapper = new EntityWrapper<>();
        //"是否审核 0未审核、1打回、2审核通过、3审核失败"
        //类型 0注册，1开店，2资质变更，3新增品牌，4新增类目"
        wrapper.eq("shop_id", shopId).eq("brand_id", brandId).eq("status",0);
        wrapper.andNew().eq("type", 4).or().eq("type", 3);
        List<ShopCategoryRelationAuditDTO> dtos = shopCategoryRelationAuditService.selectList(wrapper);
        return new Result<>(dtos);
    }

    @PostMapping("/addCategory")
    @ApiOperation(value = "提交新增品牌类目审核",notes = "提交新增品牌类目审核")
    public Result addCategory(ShopCategoryRelationAuditSaveListBO bo){
        if(bo.getShopId() == null){
            return new Result<>(CodeEnum.FAIL_100002 );
        }

        shopCategoryRelationAuditService.addCategory(bo);

        return new Result<>();
    }

}
